from typing import List


class Solution:
    def nextGreaterElements(self, nums: List[int]) -> List[int]:
        n = len(nums)
        nums_repeat = nums * 2
        stack = []
        next_gt = [-1] * len(nums_repeat)
        for idx in range(0, len(nums_repeat)):
            while stack and nums_repeat[idx] > nums_repeat[stack[-1]]:
                next_gt[stack.pop()] = idx % n
            stack.append(idx)
        # print(next_gt)

        ret = []
        for i in range(0, n):
            if next_gt[i] == -1:
                ret.append(-1)
            else:
                ret.append(nums_repeat[next_gt[i]])
        return ret